//
//  Instance MethodsTests.m
//  GeneralDiveUtilitiesTestHarness
//
//  Created by Donald MacKay on 11-04-22.
//  Copyright 2011 President, Northern Tech Diver Corporation. All rights reserved.
//

#import "InstanceMethodsTests.h"


@implementation InstanceMethodsTests

#if USE_APPLICATION_UNIT_TEST     // all code under test is in the iPhone Application



#else                           // all code under test must be linked into the Unit Test

- (void)testInitAsNitrox {

    NSLog(@"************ Running Test Case testInitAsStdGas imperial ***************");

    NSError *error;
    
    /***
     * Create some GasMix Objects to play with
     */
    int arrayCap = 4;
    double nitroxfO2 = 0.32;
    NSMutableArray *nitroxArray = [[NSMutableArray alloc] initWithCapacity:arrayCap];
    
    NSEnumerator *e;
    e = [nitroxArray objectEnumerator];
    id element = nil;
    
    for(int i = 0; i < arrayCap; i++){
        GasMix *theMix = [[GasMix alloc] initAsNitrox:nitroxfO2 error:&error];
        [nitroxArray addObject:theMix];
        
        [theMix release];
        nitroxfO2 += 0.02;
    }
    
    while ((element = [e nextObject])){
        NSLog(@"%@", element);
        NSLog(@"The MOD for this mix is %1.0f", [element MOD:1.2 isMetric:FALSE]);
        NSLog(@"The ppO2 for this mix at 100 feet is %1.2f", [element ppO2:100 isMetric:FALSE]);
        NSLog(@"The END for this mix at 100 feet is %1.2ld", [element ENDofGas:100 isMetric:FALSE]);
        NSLog(@"The EAD for this mix at 100 feet is %1.2ld", [element EADofGas:100 isMetric:FALSE]);
    }
    [nitroxArray release];
    nitroxArray = nil;
    e = nil;
}

- (void)testInitAsTrimix {

    NSLog(@"************ Running Test Case testInitAsTrimix ***************");

    NSError *error;
        
    int arrayCap = 5;
    double trimixfO2 = 0.21;
    double fracOfHe = 0.35;
    NSMutableArray *trimixArray = [[NSMutableArray alloc] initWithCapacity:arrayCap];
    
    NSEnumerator *e;
    id element = nil;
    
    e = [trimixArray objectEnumerator];
    
    for(int i = 0; i < arrayCap; i++){
        GasMix *theMix = [[GasMix alloc] initAsTriMixWithFO2:trimixfO2 andFractionOfHelium:fracOfHe error:&error];
        [trimixArray addObject:theMix];
        
        [theMix release];
        trimixfO2 -= 0.03;
        fracOfHe += 0.10;
    }
    double depth = 150.0;
    while ((element = [e nextObject])){
        NSLog(@"%@", element);
        NSLog(@"The MOD for this mix is %1.0f", [element MOD:1.2 isMetric:FALSE]);
        NSLog(@"The ppO2 for this mix at %1.0f feet is %1.2f", depth, [element ppO2:depth isMetric:FALSE]);
        NSLog(@"The END for this mix at %1.0f feet is %1.2ld", depth, [element ENDofGas:depth isMetric:FALSE]);
        
        depth +=50.0;
    }
    
    [trimixArray release];
    trimixArray = nil; 
}
/***
 * The following methods test the direct creation of GasMix objects by
 * their standard gas name
 */
-(void) testInitAsStdGas {

    NSLog(@"************ Running Test Case testInitAsStdGas metric ***************");
    
    NSMutableArray *stdGasArray = [[NSMutableArray alloc] initWithCapacity:6];
    
    GasMix *mix = [[GasMix alloc] initAsTriOx];
    [stdGasArray addObject:mix];
    [mix release];
    
    mix = [[GasMix alloc] initAs21_35];
    [stdGasArray addObject:mix];
    [mix release];
    
    mix = [[GasMix alloc] initAs18_45];
    [stdGasArray addObject:mix];
    [mix release];
    
    mix = [[GasMix alloc] initAs15_55];
    [stdGasArray addObject:mix];
    [mix release];
    
    mix = [[GasMix alloc] initAs12_65];
    [stdGasArray addObject:mix];
    [mix release];
    
    mix = [[GasMix alloc] initAs10_70];
    [stdGasArray addObject:mix];
    [mix release];

    for (id element in stdGasArray) {
        NSLog(@"%@", element);
        NSLog(@"The MOD for this mix is %1.0f", [element MOD:1.2 isMetric:TRUE]);
    }
        
    [stdGasArray release];
    stdGasArray = nil;
}

-(void)testInitWithStdGasForDepth {

    NSLog(@"************ Running Test Case testInitWithStdGasForDepth metric ***************");

    NSError *error;
    
    /* Test a depth too shallow */
    NSLog(@"**************** Test a depth of 0 meters ******************");
    GasMix *theMix = [[GasMix alloc] initWithStdGasForDepth:0.0 isMetric:TRUE error:&error];
    if(error) {
        NSLog(@"%@", error);
    }
    else {
        NSLog(@"%@", theMix);
    }
    error = nil;
    [theMix release];

    NSLog(@"***************** Test a depth of 0 feet ********************");
    theMix = [[GasMix alloc] initWithStdGasForDepth:0.0 isMetric:FALSE error:&error];
    if(error) {
        NSLog(@"%@", error);
    }
    else {
        NSLog(@"%@", theMix);
    }
    error = nil;
    [theMix release];
    
    /* Test a depth too deep */
    NSLog(@"***************************Test a depth of 130 meters************************");
    theMix = [[GasMix alloc] initWithStdGasForDepth:130 isMetric:TRUE error:&error];
    if(error) {
        NSLog(@"%@", error);
    }
    else {
        NSLog(@"%@", theMix);
    }    
    error = nil;
    [theMix release];

    /* Test a depth too deep */
    NSLog(@"***************************Test a depth of 331 feet************************");
    theMix = [[GasMix alloc] initWithStdGasForDepth:331 isMetric:FALSE error:&error];
    if(error) {
        NSLog(@"%@", error);
    }
    else {
        NSLog(@"%@", theMix);
    }    
    error = nil;
    [theMix release];

    NSLog(@"***************************Range Test************************");
    NSMutableArray *mixArray = [[NSMutableArray alloc] init];
    int tmpDepth = 4;
    while (TRUE) { // Iterate until depth limit is reached
        theMix = [[GasMix alloc] initWithStdGasForDepth:tmpDepth isMetric:FALSE error:&error];
        if (error) {
            NSLog(@"GasMix initWithStdGasForDepthLimit reached %@", error);
            break;
        }
        [mixArray addObject:theMix];
        
        [theMix release];
        tmpDepth++;
    }
    
    for (id element in mixArray) {
        NSLog(@"%@", element);
    }
    
    [mixArray release];
}

#endif

@end
